import request from '@/utils/request'
// import { praseStrEmpty } from "@/utils/zhaoxi";

// 查询博客信息列表
export function listBlog(query) {
    return request({
        url: '/cms/blog/list',
        method: 'get',
        params: query
    })
}

// 查询博客信息详细
export function getBlog(id) {
    return request({
        url: '/cms/blog/' + id,
        method: 'get'
    })
}

// 新增博客信息
export function addBlog(data) {
    return request({
        url: '/cms/blog',
        method: 'post',
        data: data
    })
}

// 修改博客信息
export function updateBlog(data) {
    return request({
        url: '/cms/blog',
        method: 'put',
        data: data
    })
}

// 删除博客信息
export function delBlog(id) {
    return request({
        url: '/cms/blog/' + id,
        method: 'delete'
    })
}

// 首页查询文章列表
export function cmsListBlog(query) {
    return request({
        url: '/cms/blog/cms/cmsList',
        method: 'get',
        params: query,
    })

}

// 首页按分类查询文章列表
export function cmsListByTypeId(id) {
    return request({
        url: '/cms/blog/cms/cmsListByType/' + id,
        method: 'get',
    })
}

// 首页按标签查询文章列表
export function cmsListByTagId(id) {
    return request({
        url: '/cms/blog/cms/cmsListByTag/' + id,
        method: 'get',
    })
}

// 首页查询推荐文章列表
export function cmsListRecommend(query) {
    return request({
        url: '/cms/blog/cms/cmsListRecommend',
        method: 'get',
        params: query,
    })
}

// 首页查询文章详细
/*export function getBlogDetail(id) {
    return request({
        url: '/cms/blog/cms/detail/' + parseStrEmpty(id),
        method: 'get',
    })
}*/


/*export function getBlogDetail(id) {
    const url = id ? '/cms/blog/cms/detail/' + id : '/cms/blog/cms/detail';
    return request({
        url: url,
        method: 'get',
    });
}*/

function parseStrEmpty(value) {
    if (value === null || value === undefined || value === '') {
        return '';
    } else {
        return value.toString();
    }
}

export function getBlogDetail(id) {
    return request({
        url: '/cms/blog/cms/detail/' + parseStrEmpty(id),
        method: 'get',
    })
}
